package com.zhaojonhy.zhaopangwb.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.zhaojonhy.zhaopangwb.R;
import com.zhaojonhy.zhaopangwb.bean.Statuses;
import com.zhaojonhy.zhaopangwb.bean.userFriendShips.UserBean;
import com.zhaojonhy.zhaopangwb.ui.UserInfoActivity;
import com.zhaojonhy.zhaopangwb.utils.ImageOptHelper;
import com.zhaojonhy.zhaopangwb.utils.StringUtils;
import com.zhaojonhy.zhaopangwb.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/25.
 */

public class StatusFriendAdapter extends BaseAdapter {

    private static final String TAG = UserInfoActivity.class.getSimpleName() ;
    private Activity activity ;
    private List<UserBean> users ;
    private ImageLoader imageLoader ;

    public StatusFriendAdapter(Activity activity , List<UserBean> users ) {
        this.activity = activity ;
        this.users = users ;
        imageLoader = ImageLoader.getInstance() ;
    }

    @Override
    public int getCount() {
        return users.size() ;
    }

    @Override
    public UserBean getItem(int position) {
        return users.get(position) ;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder ;
        if (convertView == null){
            holder = new Holder() ;
            convertView = View.inflate(activity, R.layout.items_friends,null) ;
            holder.ll_card_content = (LinearLayout)convertView.findViewById(R.id.ll_card_content) ;
            holder.iv_avatar = (ImageView)convertView.findViewById(R.id.iv_avatar) ;
            holder.tv_subhead = (TextView)convertView.findViewById(R.id.tv_subhead) ;
            holder.tv_content = (TextView)convertView.findViewById(R.id.tv_content) ;

            convertView.setTag(holder);
        }else{
            holder = (Holder) convertView.getTag() ;
        }

        final UserBean user = getItem(position) ;
        imageLoader.displayImage(user.getAvatar_large(),holder.iv_avatar, ImageOptHelper.getAvatarOptions());
        holder.tv_subhead.setText(user.getName());
        holder.tv_content.setText(StringUtils.getWeiboContent(
                activity, holder.tv_content,user.getStatus().getText()));

        holder.ll_card_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showToast(activity,("你的好友："+ user.getName() ) , Toast.LENGTH_LONG);
            }
        });
        return convertView;
    }

    class Holder{
        private LinearLayout ll_card_content ;
        private ImageView iv_avatar ;
        private TextView tv_subhead ;
        private TextView tv_content ;
    }

}
